<%@ page language="java" contentType="text/html;charset=UTF-8" pageEncoding="UTF-8"%>
<%@ taglib uri="/struts-tags" prefix="s"%>
<%
	String path = request.getContextPath();
	String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";
%>
<!DOCTYPE html>
<html>
<head>
	<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
	<title>角色授权用户管理</title>
	<link type="text/css" rel="stylesheet" href="../<s:property value="#session.themeStyle.mainCss" default="Skin/PM/cyan/main.css"/>" />
	<link type="text/css" rel="stylesheet" href="../css/zTreeStyle/zTreeStyle.css" />
	<link type="text/css" rel="stylesheet" href="../css/jquery.loadmask.css">
</head>
<body>
	<s:form theme="simple">
	<div class="navBar">
				当前位置：系统管理&nbsp;&gt;&gt;&nbsp;角色权限管理&nbsp;&gt;&gt;&nbsp;角色授权用户管理
		</div>
	<div class="tabBlock">
		<span style="font-weight: bold;">角色</span>：<s:property value="role.name"/>
		<s:hidden id="roleId" name="roleId"/>
		<div style="margin-top: 10px;" >
			组织机构：<s:select id="orgId" name="orgId" list="managedOrgList" listKey="pkId" listValue="name" emptyOption="managedOrgList.size>1" onchange="$(\"form\")[0].submit()"></s:select>
			<a class="but28" onclick="addRoleUser(<s:property value="role.pkId"/>,this)" style="text-decoration:none;" >添加用户</a>
		</div>
		<input type="hidden" id="state" value="<s:property value="state"/>" />
			<div class="dataGrid" style="margin-top: 10px;">
				<table>
					<tr>
						<th style="width: 20%;white-space: nowrap;">
							姓名
						</th>
						<th style="width: 20%;white-space: nowrap;">
							账号
						</th>
						<th style="width: 30%;white-space: nowrap;">
							部门
						</th>
						<th style="width: 20%;white-space: nowrap;">
							用户状态
						</th>
						<th style="width: 15%;white-space: nowrap;">
							操作
						</th>
					</tr>
					<s:iterator value="userList" status="st">
						<tr class="trStyle">
							<td>
								<s:property value="name" />&nbsp;
							</td>
							<td>
								<s:property value="userName" />&nbsp;
							</td>
							<td>
								<s:property value="userDept" />&nbsp;
							</td>
							<td>
								<s:if test="type==0">
									无效
								</s:if>
								<s:else>
									有效&nbsp;
								</s:else>
							</td>
							<td>
								<a href='##' onclick='deleteUserRole(<s:property value="pkId"/>, this,"<s:property value="name"/>","<s:property value="role.name"/>")' style="color:#E9621E;">删除</a>&nbsp;
							</td>
						</tr>
					</s:iterator>
						<tr class="trStyle" style="<s:if test="userList.size>0">display: none;</s:if>">
							<td colspan="5">
								没有任何授权用户&nbsp;
							</td>
						</tr>
				</table>
			</div>
	</div>
	<div class="toolbar" style="text-align: center;">
		<a class="but28" href="roleInfo-manage.action" style="text-decoration:none;">返回</a>
	</div>
	</s:form>
	<script type="text/javascript" src="../js/jquery.js"></script>
	<script type="text/javascript" src="../js/jquery.loadmask.min.js"></script>
	<script type="text/javascript" src="../js/ztree/jquery.ztree.core-3.5.js"></script>
	<script type="text/javascript" src="../js/ztree/jquery.ztree.excheck-3.5.js"></script>
	<script type="text/javascript" src="../js/modalWindow.js"></script>
	<script type="text/javascript" src="../js/store.js"></script>
	<script type="text/javascript" src="../js/RoleFuncManage.js"></script>
	<script type="text/javascript">
		
		var setting = {
			async: {
                enable: true,
                url:"userRole-loadSubNodes.action",
                autoParam:["id", "name", "level"],
                otherParam:{"otherParam":"zTreeAsyncTest"},
                dataFilter: filter,
                type: "post"  
            },
			check: {
				enable: true
			},
			data: {
				simpleData: {
					enable: true
				}
			},
			callback: {
				onClick: onClick,
				beforeAsync: beforeAsync,
				onAsyncSuccess: zTreeOnAsyncSuccess
			}
		};
	
		$(document).ready(function(){
			var treeObj = $.fn.zTree.init($("#ultree"), setting);
			initWindow();
		});
		
        function filter(treeId, parentNode, childNodes) {
            if (!childNodes) return null;
            for (var i=0, l=childNodes.length; i<l; i++) {
                childNodes[i].name = childNodes[i].name.replace(/\.n/g, '.');
            }
            return childNodes;
        }
  
        function beforeAsync() {
            curAsyncCount++;
        }
        
		function onClick(event, treeId, treeNode, clickFlag) {
			var deptId = treeNode.deptId;
			if ('undefined'==typeof(deptId)){
				deptId = 0;
			};
			var html = "";
			html += "<iframe id=\"deptFrame\" name=\"deptFrame\" src=\"../sys/deptInfo-manage.action?deptId="+deptId+"\" frameborder=\"0\" scrolling=\"yes\" style=\"width:100%;\"  onLoad=\"this.height=this.contentWindow.document.documentElement.scrollHeight\" ></iframe>";
			html += "<iframe id=\"deptFrame\" name=\"deptFrame\" src=\"../sys/userInfo-manage.action?deptId="+deptId+"\"frameborder=\"0\" scrolling=\"yes\" style=\"width:100%;\"   onLoad=\"this.height=this.contentWindow.document.documentElement.scrollHeight\"></iframe>";

			$("#showList").html(html); 			
		}
		
		function refreshTree(){
			var zTree = $.fn.zTree.getZTreeObj("ultree");
			if (currentNode!=null){
				alert("刷新"+currentNode.name);
				zTree.reAsyncChildNodes(null, "refresh");
			}else{
				alert("刷新空！");
				zTree.reAsyncChildNodes(null, "refresh");
			} 
		}
		
		var curStatus = "init", curAsyncCount = 0, goAsync = false;
		var currentNode = null;
		function zTreeOnAsyncSuccess(event, treeId, treeNode, msg) {
			curAsyncCount--;
			// 当前节点是否已经处理
			var currentNodeId = $("#currentNodeId").val();
			if (currentNodeId==""){
				// 默认处理
				if (treeNode==null){
					var treeObj = $.fn.zTree.getZTreeObj(treeId);//获取ztree对象
					var currentNode = treeObj.getNodesByFilter(function (node) { return node.level == 0 }, true);
					if (currentNode!=null){
						$("#currentNodeId").val(currentNode.id);
						treeObj.selectNode(currentNode);
						onClick(event, treeId, currentNode);
						treeObj.expandNode(currentNode, true, false, false);
					}
				}				
			}else{
				// 
			}
			if(currentNode==null){
				// 未处理
				var treeObj = $.fn.zTree.getZTreeObj(treeId);
				currentNode = treeObj.getNodeByParam("id", currentNodeId);
				if (currentNode){
					treeObj.selectNode(currentNode);
					onClick(event, treeId, currentNode);
				}else{
				}
			}
			if (treeNode==null){
				var treeObj = $.fn.zTree.getZTreeObj(treeId);//获取ztree对象
				var node = treeObj.getNodesByFilter(function (node) { return node.level == 0 }, true);
				if (node!=null){
					treeObj.expandNode(node, true, false, false);
				}
			}else{
				if (curStatus == "expand") { 
					expandNodes(treeNode.children);
					alert("expand");
				} else if (curStatus == "async") { 
					asyncNodes(treeNode.children); 
					alert("async");
				}else if(curStatus == "init"){
				}else{
					
				}
			}
			
			if (curAsyncCount <= 0) { 
			  curStatus = ""; 
			}
			
		}
		
		function expandAll() { 
			if (!asyncComplate()) { 
				return; 
			} 
			var zTree = $.fn.zTree.getZTreeObj("ultree"); 
			expandNodes(zTree.getNodes()); 
			if (!goAsync) { 
				curStatus = ""; 
			}
		}
		
		function expandNodes(nodes) {
			if (!nodes) return;
			curStatus = "expand";
			var zTree = $.fn.zTree.getZTreeObj("ultree");
			for (var i=0, l=nodes.length; i<l; i++) {
				zTree.expandNode(nodes[i], true, false, false);//展开节点就会调用后台查询子节点
				if (nodes[i].isParent && nodes[i].zAsync) {
					expandNodes(nodes[i].children);//递归
				} else {
					goAsync = true;
				}
			}
		}

		function asyncComplate() {
			if (curAsyncCount > 0) {
				return false;
			}
			return true;
		}
 
		function initWindow(){
			if (window.top!=window.self){
				var height = window.parent.document.getElementById("mainFrame").height-2;
				var width = window.parent.document.getElementById("mainFrame").width-2;
				$("#divMain").height(height-50);
				$("#divMain").width(width-20);
				$("#divTree").height(height-57);
				$("#showList").height(height-57);
				$("#divTable11").height(height/2-35);
				$("#divTable22").height(height/2-35);
				if($("#divMain").width()<1110){
					$("#divMain").width(1110);
				}
			}
			$("showList").empty();
		}
		
		function deleteUserRole(userId,obj,name,roleName){
			if(confirm("确定要解除用户["+name+"]的["+roleName+"]授权？")){
				var roleId = $("#roleId").val(); 
				$.post("userRole-del.action", { roleId: roleId, userId: userId },
				  	function(data){
				    	$(obj).parent().parent().remove();
				});
			}
			
		}
		
	</script>
</body>
</html>
